﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <script src="../../js/load.js"></script>
</head>

<body>
    <div id="container">
        <div id="formcontainer">
            <form class="layui-form layui-form-pane" id="editform" lay-filter="editform">
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label required">项目名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="projectName" autocomplete="off" class="layui-input required">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label required">服务名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="serviceName" autocomplete="off" class="layui-input required">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label required">端口号</label>
                            <div class="layui-input-block">
                                <input type="text" name="warPort" autocomplete="off" class="layui-input required number">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label required">映射路由</label>
                            <div class="layui-input-block">
                                <input type="text" name="contextPath" autocomplete="off" class="layui-input required" value="/">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label required">初始内存</label>
                            <div class="layui-input-block">
                                <input type="text" name="initMemorySize" autocomplete="off" class="layui-input required number" value="512">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label required">最大内存</label>
                            <div class="layui-input-block">
                                <input type="text" name="maxMemorySize" autocomplete="off" class="layui-input required number" value="1024">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label">跳过扫描</label>
                            <div class="layui-input-block">
                                <input type="text" name="skipScan" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label">服务依赖</label>
                            <div class="layui-input-block">
                                <div id="dependService">

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">部署备注</label>
                            <div class="layui-input-block">
                                <textarea name="depolyRemark" autocomplete="off" class="layui-textarea"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div id="opcontainer">
            <button class="layui-btn" onclick="HandleSave()">确认</button>
            <button class="layui-btn layui-btn-primary" onclick="HandleClose()">关闭</button>
        </div>
    </div>
</body>
</html>
<script>
    var dependService = null;
    $(function () {
        initService();
    })

    function HandleSave() {
        SubmitForm('editform', 'api/war/insert', BeforeSubmit, null, function (result, status) {
            if (result.code == 0) {
                OpenSuccess('添加成功', function (params) {
                    CloseDialog();
                })
            } else {
                OpenFail(result.msg);
            }
        })
    }

    function BeforeSubmit(data) {
        var serviceList = dependService.getValue('name');
        data.dependService = serviceList.join("|");
        return true;
    }

    function HandleClose() {
        CloseDialog();
    }

    function initService() {
        var param = {
            pageIndex:1,
            pageSize:500
        }
        HttpPost(JSON.stringify(param), 'api/service/list', function (result) {
            if (result.code == 0) {
                var serviceList = result.data.rows;
                var data = [];
                for (var i=0;i<serviceList.length;i++){
                    data.push(   {name: serviceList[i].serviceName, value: serviceList[i].serviceName})
                }
                dependService = xmSelect.render({
                    el: '#dependService',
                    filterable: true,
                    data: data
                })
            }
        })

    }
</script>